package ${package.Controller};

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.wsd.jing.annotation.ControllerLog;
import ${package.Entity}.${entity};
import com.wsd.jing.request.CommonRequest;
import com.wsd.jing.request.CommonResponse;
import ${package.Service}.${table.serviceName};
import com.wsd.jing.validator.group.InsertGroup;
import com.wsd.jing.validator.group.UpdateGroup;
<#if swagger>
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
</#if>
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.*;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * All rights Reserved, Designed By www.tom.com
 *
 * @author ${author}
 * @version 1.0.0
 * @projectName: ${project}
 * @packageName: ${package.Controller}
 * @className: ${table.controllerName}
<#assign entityName = "">
<#if (table.comment?? && table.comment != '')>
    <#if table.comment?ends_with("表")>
        <#assign entityName = table.comment?substring(0,table.comment?length-1)>
    <#else>
        <#assign entityName = table.comment>
    </#if>
<#else>
    <#assign entityName = table.entityName>
</#if>
 * @description: ${entityName!}前端控制器
 * @createDate ${date}
 * @copyright ${date} www.tom.com Inc. All rights reserved.
 */
<#if swagger>
@Api(tags = "${entityName!}")
</#if>
@Validated
@Slf4j
@RequiredArgsConstructor
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("/rest<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    private final I${entity}Service ${entity?uncap_first}Service;

    <#if swagger>
    @ApiOperation(value = "新增")
    </#if>
    @PostMapping()
    @ControllerLog(action = "新增${entityName!}", message = "新增${entityName!}失败")
    @SaCheckPermission("${entity?uncap_first}:add")
    public CommonResponse insert${entity}(@Validated(InsertGroup.class) @RequestBody ${entity} ${entity?uncap_first}) {
        return CommonResponse.success(${entity?uncap_first}Service.insert${entity}(${entity?uncap_first}), "新增成功");
    }

    <#if swagger>
    @ApiOperation(value = "修改")
    </#if>
    @PutMapping()
    @ControllerLog(action = "修改${entityName!}", message = "修改${entityName!}失败")
    @SaCheckPermission("${entity?uncap_first}:update")
    public CommonResponse update${entity}(@Validated(UpdateGroup.class) @RequestBody ${entity} ${entity?uncap_first}) {
        return CommonResponse.success(${entity?uncap_first}Service.update${entity}(${entity?uncap_first}), "修改成功");
    }

    <#if swagger>
    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "id", value = "${entityName!}id", paramType = "path", dataType = "Integer", required = true)
    </#if>
    @DeleteMapping("/{id}")
    @ControllerLog(action = "删除${entityName!}", message = "删除${entityName!}失败")
    @SaCheckPermission("${entity?uncap_first}:delete")
    public CommonResponse delete${entity}(@PathVariable("id") Integer id) {
        return CommonResponse.success(${entity?uncap_first}Service.delete${entity}(id), "删除成功");
    }

    <#if swagger>
    @ApiOperation(value = "批量删除")
    @ApiImplicitParam(name = "ids", value = "${entityName!}id逗号分割字符", paramType = "query", dataType = "String", required = true)
    </#if>
    @DeleteMapping("")
    @ControllerLog(action = "批量删除${entityName!}", message = "批量删除${entityName!}失败")
    @SaCheckPermission("${entity?uncap_first}:batch:delete")
    public CommonResponse delete${entity}s(@RequestParam("ids") String ids) {
        return CommonResponse.success(${entity?uncap_first}Service.delete${entity}s(ids), "批量删除成功");
    }

    <#if swagger>
    @ApiOperation(value = "查询")
    @ApiImplicitParam(name = "id", value = "${entityName!}id", paramType = "path", dataType = "Integer", required = true)
    </#if>
    @GetMapping("/{id}")
    @ControllerLog(action = "查询${entityName!}", message = "查询${entityName!}失败")
    @SaCheckPermission("${entity?uncap_first}:get")
    public CommonResponse get${entity}(@PathVariable("id") Integer id) {
        return CommonResponse.success(${entity?uncap_first}Service.get${entity}(id), "查询成功");
    }

    <#if swagger>
    @ApiOperation(value = "查询列表")
    </#if>
    @GetMapping("/list")
    @ControllerLog(action = "查询${entityName!}列表", message = "查询${entityName!}列表失败")
    @SaCheckPermission("${entity?uncap_first}:list")
    public CommonResponse list${entity}s(CommonRequest commonRequest, ${entity} ${entity?uncap_first}) {
        return CommonResponse.success(${entity?uncap_first}Service.list${entity}s(commonRequest, ${entity?uncap_first}), "查询成功");
    }

    <#if swagger>
    @ApiOperation(value = "分页查询")
    </#if>
    @GetMapping("/pages")
    @ControllerLog(action = "分页查询${entityName!}", message = "分页查询${entityName!}失败")
    @SaCheckPermission("${entity?uncap_first}:page")
    public CommonResponse listPage${entity}s(CommonRequest commonRequest, ${entity} ${entity?uncap_first}) {
        return CommonResponse.success(${entity?uncap_first}Service.listPage${entity}s(commonRequest, ${entity?uncap_first}), "查询成功");
    }
}
</#if>
